﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Krist_em_up.Characters;
using Krist_em_up.Item.Projectiles;

namespace Krist_em_up.Item.Weapons
{
    /// <summary>
    /// Weapon which fire 3 bullets at the same time
    /// One to the front-top direction one to the front-bottom direction and one in the same direction as the character
    /// </summary>
    class ScatterGun : Gun
    {

        public ScatterGun(int owner, Kristemup k)
            : base(owner, k)
        {
            this.Name = "Scatter Gun";
            this.Ammunition = 50;
        }

        /// <summary>
        /// Pull the trigger nigga!
        /// </summary>
        /// <param name="position">Position where the weapon shoot</param>
        /// <param name="direction">True for right, false for left</param>
        public override void Shoot(Vector2 position, bool direction)
        {
            if (reloadTimer <= TimeSpan.Zero)
            {
                try
                {
                    Ammunition--;
                    GunBullet balle;
                    if (direction)
                    {
                        balle = new GunBullet(owner, game, new Vector2(position.X + Kris.WIDTH, position.Y + Kris.HEIGHT / 2+10), new Vector2(1, 0));
                        game.bullets.Add(balle);

                        balle = new GunBullet(owner, game, new Vector2(position.X + Kris.WIDTH, position.Y + Kris.HEIGHT / 2+10), new Vector2(1, .5f));
                        balle.Speed = new Vector2(15f);
                        game.bullets.Add(balle);

                        balle = new GunBullet(owner, game, new Vector2(position.X + Kris.WIDTH, position.Y + Kris.HEIGHT / 2+10), new Vector2(1, -.5f));
                        balle.Speed = new Vector2(15);
                        game.bullets.Add(balle);
                    }
                    else
                    {
                        balle = new GunBullet(owner, game, new Vector2(position.X, position.Y + Kris.HEIGHT / 2+10), new Vector2(-1, 0));
                        game.bullets.Add(balle);

                        balle = new GunBullet(owner, game, new Vector2(position.X, position.Y + Kris.HEIGHT / 2+10), new Vector2(-1, .5f));
                        balle.Speed = new Vector2(15f);
                        game.bullets.Add(balle);

                        balle = new GunBullet(owner, game, new Vector2(position.X, position.Y + Kris.HEIGHT / 2+10), new Vector2(-1, -.5f));
                        balle.Speed = new Vector2(15);
                        game.bullets.Add(balle);
                    }
                }
                catch (NoAmmoException) { }

                this.reloadTimer = new TimeSpan(0, 0, 0, 0, 300);
            }

        }
    }
}
